#include <vector>

class Game {
    using VertexNo = int;
    std::vector<std::vector<VertexNo>> transfer_to_by_choice;
    std::vector<VertexNo> save;
    VertexNo current_pos = 0;
public:
    Game() = delete;
    Game(int N) : save(100, -1), transfer_to_by_choice(N) {}
    void add_choice(VertexNo from, VertexNo to, int i) {
        transfer_to_by_choice[from].push_back(to);
    }
    void do_choice(int i) {
        current_pos = transfer_to_by_choice[current_pos][i];
    }
    void save_to(int i) {
        save[i] = current_pos;
    }
    auto get_current_pos() {
        return current_pos;
    }
    auto read_from(int i) {
        current_pos = save[i];
    }
};

#include <iostream>

int main() {

    int N, M;
    std::cin >> N >> M;
    
    Game inst(N);

    for (int i = 0; i < N; ++i) {
        int choice_cnt;
        std::cin >> choice_cnt;
        for (int choice_idx = 0; choice_idx < choice_cnt; ++choice_idx) {
            int to;
            std::cin >> to;
            inst.add_choice(i, to-1, choice_idx);
        }
    }

    enum class OP {
        DO = 0,
        SAVE = 1,
        READ = 2
    };

    for (int i = 0; i < M; ++i) {
        int op_no, operand;
        std::cin >> op_no >> operand;
        auto op = static_cast<OP>(op_no);
        if (op == OP::DO) {
            inst.do_choice(operand - 1);
        } else if (op == OP::SAVE) {
            inst.save_to(operand - 1);
            std::cout << inst.get_current_pos() + 1 << "\n";
        } else if (op == OP::READ) {
            inst.read_from(operand - 1);
        }
    }
    std::cout << inst.get_current_pos() + 1 << "\n";
}
